package com.ddsso.auth.web.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ddsso.auth.web.util.HttpServletHolder;

/**
 * @author zdd
 * @package com.ddsso.auth.web.filter
 * @Time Created by zdd on 2016/11/2.
 * @description 设置HTTP SERVLET请求和响应持有者本地线程变量
 */
public class HttpServletHolderFilter extends BaseFilter {
    /**
     * (non-Javadoc)
     *
     */
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
        try {
            String uniqueId = request.getHeader(HttpServletHolder.UNIQUE_ID_HEADER_NAME);
            HttpServletHolder.set(request, response, uniqueId);
            filterChain.doFilter(request, response);
        } finally {
            HttpServletHolder.remove();
        }
    }
}
